/////////////////////////////////////////////////////////////////////////
//
// Amuse Engine SDK - memory
// Copyright( c) 2015.  All Rights Reserved
//
// File:		AERefCounter.h
// Author:		Gianluca Belardelli
// Date:		11/05/2015
//
/////////////////////////////////////////////////////////////////////////
#ifndef _AEREFCOUNTER_H_
#define _AEREFCOUNTER_H_

class AERefCounter : public AEBaseObject
{
// Members
protected:
	AEINT32 m_nRefCount;  ///<reference count
// Methods
protected:
public:
	/// Creates a new referenced object with an initial reference count of 1.
	AE_FORCEINLINE AERefCounter( void );

	/// Copy constructor, any default subclass's copy constructor will correctly initialize reference count to 1.
	AE_FORCEINLINE AERefCounter( const AERefCounter &originalObject );

	/// Destroy this object.
	AE_FORCEINLINE virtual ~AERefCounter( void );

	/// Empty assignment operator - the reference count of this will remain unchanged.
	//AE_FORCEINLINE void operator=( const AEReferencedObject &originalObject );
	AE_FORCEINLINE  AERefCounter &operator=( const AERefCounter &originalObject );

	/// Returns the current reference count. Used for debugging only.
	AE_FORCEINLINE AEINT32 GetReferenceCount( void ) const;

	/// Adds a reference to the object - this increments the reference count.
	/// ###ACCESS_CHECKS###( [(&hkReferencedObjectLock::getInstance()),HK_ACCESS_RW] );
	AE_FORCEINLINE void AddRef( void ) const;

	/// Removes a reference to the object - this decrements the last reference count.
	/// ###ACCESS_CHECKS###( [(&hkReferencedObjectLock::getInstance()),HK_ACCESS_RW] );
	AE_FORCEINLINE void Release( void );

	AE_FORCEINLINE void ReleaseNoDelete( void );
	
	/// \brief
	///   Overridable function that is called when the refcounter reaches zero. The default
	///   implementation calls "delete this".
	AE_FORCEINLINE virtual void DeleteThis( void );
};

#include "AERefCounter.inl"

#endif // _AEREFCOUNTER_H_
